package com.ruoyi.organization.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.BizCommunity;
import com.ruoyi.organization.domain.BizGrid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.organization.service.IBizCommunityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区设置Controller
 * 
 * @author ruoyi
 * @date 2024-05-06
 */
@RestController
@RequestMapping("/organization/community")
public class BizCommunityController extends BaseController
{
    @Autowired
    private IBizCommunityService bizCommunityService;

    /**
     * 查询社区设置列表
     */
    @PreAuthorize("@ss.hasPermi('organization:community:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCommunity bizCommunity)
    {
        startPage();
        List<BizCommunity> list = bizCommunityService.selectBizCommunityList(bizCommunity);
        return getDataTable(list);
    }

    /**
     * 导出社区设置列表
     */
    @PreAuthorize("@ss.hasPermi('organization:community:export')")
    @Log(title = "社区设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCommunity bizCommunity)
    {
        List<BizCommunity> list = bizCommunityService.selectBizCommunityList(bizCommunity);
        ExcelUtil<BizCommunity> util = new ExcelUtil<BizCommunity>(BizCommunity.class);
        util.exportExcel(response, list, "社区设置数据");
    }

    /**
     * 获取社区设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('organization:community:query')")
    @GetMapping(value = "/{communityId}")
    public AjaxResult getInfo(@PathVariable("communityId") Long communityId)
    {
        return success(bizCommunityService.selectBizCommunityByCommunityId(communityId));
    }

    /**
     * 新增社区设置
     */
    @PreAuthorize("@ss.hasPermi('organization:community:add')")
    @Log(title = "社区设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCommunity bizCommunity)
    {
        bizCommunity.setCreateBy(getUsername());
        return toAjax(bizCommunityService.insertBizCommunity(bizCommunity));
    }

    /**
     * 修改社区设置
     */
    @PreAuthorize("@ss.hasPermi('organization:community:edit')")
    @Log(title = "社区设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCommunity bizCommunity)
    {
        bizCommunity.setUpdateBy(getUsername());
        return toAjax(bizCommunityService.updateBizCommunity(bizCommunity));
    }
    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('organization:community:edit')")
    @Log(title = "状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BizCommunity community)
    {
        community.setUpdateBy(getUsername());
        return toAjax(bizCommunityService.updateBizCommunity(community));
    }
    /**
     * 删除社区设置
     */
    @PreAuthorize("@ss.hasPermi('organization:community:remove')")
    @Log(title = "社区设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{communityIds}")
    public AjaxResult remove(@PathVariable Long[] communityIds)
    {
        return toAjax(bizCommunityService.deleteBizCommunityByCommunityIds(communityIds));
    }

    /**
     * 获取部门树列表
     */
    @PreAuthorize("@ss.hasPermi('organization:community:list')")
    @GetMapping("/communityTree")
    public AjaxResult communityTree(BizCommunity bizCommunity)
    {
        return success(bizCommunityService.selectCommunityTreeTreeList(bizCommunity));
    }
}
